<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit"/>
    <title>益农商城</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <script src="../js/showName.js" type="text/javascript" charset="utf-8"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css"/>
    <link rel="stylesheet" type="text/css" href="../css/layout.css"/>
    <link rel="stylesheet" type="text/css" href="../css/top.css"/>
    <link rel="stylesheet" type="text/css" href="../css/footer.css"/>
    <link rel="stylesheet" type="text/css" href="../css/product.css"/>
    <link rel="stylesheet" type="text/css" href="../css/imgmove.css"/>
    <script src="../js/product.js" type="text/javascript" charset="utf-8"></script>
    <script src="../js/imgmove.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<!--头部-->
<header class="header">
    <!--商城logo-->
    <div class="row">
        <div class="col-md-3">
            <a href="index.html">
                <img class="logo" src="../images/index/yinong-shop.png" alt=""/>
            </a>
        </div>
        <!--快捷选项-->
        <div class="col-md-9 top-item">
            <ul class="list-inline pull-right" id="tools">

                <li><a href="orders.html"><span class="fa fa-file-text"></span>&nbsp;订单</a></li>
                <li class="li-split">|</li>
                <li><a href="cart.html"><span class="fa fa-cart-plus"></span>&nbsp;购物车</a></li>
                <li class="li-split">|</li>
                <li>
                    <!--下列列表按钮 ：管理-->
                    <div class="btn-group">
                        <button type="button" class="btn btn-link dropdown-toggle" data-toggle="dropdown">
                            <span id="top-dropdown-btn"><span class="fa fa-gears"></span>&nbsp;个人中心 <span
                                    class="caret"></span></span>
                        </button>
                        <ul class="dropdown-menu top-dropdown-ul" role="menu">
                            <li><a href="password.html">修改密码</a></li>
                            <li><a href="userdata.html">个人资料</a></li>
                            <li><a href="upload.html">上传头像</a></li>
                            <li><a href="address.html">收货管理 </a></li>
                        </ul>
                    </div>
                </li>
                <li class="li-split">|</li>
                <li id="loginPoint">
                    <div class="btn-group">
                        <button type="button" class="btn btn-link dropdown-toggle" data-toggle="dropdown">
                            <span id="user-dropdown-btn">
                                <span id="showName"></span>
                                <span class="caret"></span>
                            </span>
                        </button>
                        <ul class="dropdown-menu top-dropdown-ul" role="menu">
                            <li><a href="login.html">退出登录</a></li>
                        </ul>
                    </div>
                </li>
            </ul>
        </div>
    </div>
</header>
<!--导航 -->
<!--分割导航和顶部-->
<div class="row top-nav">
    <div class="col-md-6">
        <ul class="nav nav-pills">
            <li>
                <a href="#"></a>
            </li>
            <li class="active"><a href="index.html"><span class="fa fa-home"></span></a></li>
            <li><a href="search.html?type=grain">谷物</a></li>
            <li><a href="search.html?type=agriculturalRawMaterials">农业原料</a></li>
            <li><a href="search.html?type=livestock">畜禽及产品</a></li>
            <li><a href="search.html?type=forest">林产品</a></li>
            <li><a href="search.html?type=fishery">渔产品</a></li>

            <li><a href="search.html?type=vegetables">蔬菜</a></li>
            <li><a href="search.html?type=MelonAndFruit">瓜果</a></li>
        </ul>
    </div>
    <div class="col-md-6">
        <form action="search.html" class="form-inline pull-right" role="form">
            <div class="form-group">
                <input type="text" class="form-control" id="search" name="search" placeholder="请输入商品名称进行搜索">
            </div>
            <button type="submit" class="btn btn-default btn-sm"><span class="fa fa-search"></span></button>
        </form>
    </div>
</div>
<!--头部结束-->
<!--导航结束-->
<!--商品信息展示开始-->
<div class="container">
    <div class="col-md-offset-1 col-md-10">
        <div class="col-md-6">
            <div data="1" class="img-big move-img col-md-12">
                <img id="product-image-1-big" src=""
                     class="img-responsive"/>
            </div>
            <div data="2" class="img-big move-img col-md-12">
                <img id="product-image-2-big" src=""
                     class="img-responsive"/>
            </div>
            <div data="3" class="img-big move-img col-md-12">
                <img id="product-image-3-big" src=""
                     class="img-responsive"/>
            </div>
            <div data="4" class="img-big move-img col-md-12">
                <img id="product-image-4-big" src=""
                     class="img-responsive"/>
            </div>
            <div data="5" class="img-big move-img col-md-12">
                <img id="product-image-5-big" src=""
                     class="img-responsive"/>
            </div>
            <div data="1" class="col-md-2 img-small">
                <img id="product-image-1" src=""
                     class="img-responsive"/>
            </div>
            <div data="2" class="col-md-2 img-small">
                <img id="product-image-2" src=""
                     class="img-responsive"/>
            </div>
            <div data="3" class="col-md-2 img-small">
                <img id="product-image-3" src=""
                     class="img-responsive"/>
            </div>
            <div data="4" class="col-md-2 img-small">
                <img id="product-image-4" src=""
                     class="img-responsive"/>
            </div>
            <div data="5" class="col-md-2 img-small">
                <img id="product-image-5" src=""
                     class="img-responsive"/>
            </div>
        </div>
        <div class="col-md-6">
            <h3 id="product-title" class="col-md-12 title-row-1"></h3>
            <p id="product-sell-point" class="col-md-12 text-row-1"><small></small></p>
            <div class="col-md-12 price-bar">
                <small>售价：</small> ¥<span id="product-price"></span>
                <div><small>*退货补运费 *7天无理由退货 *24小时快速退款 </small></div>
            </div>
            <form class="form-inline product-form col-md-12" role="form" action="orderConfirm.html">
                <div class="col-md-12 form-space">
                    <label for="num">数量：</label>
                    <input id="numDown" type="button" value="-" class="num-btn"/>
                    <input id="num" type="text" size="2" readonly="readonly" class="num-text" value="1">
                    <input id="numUp" class="num-btn" type="button" value="+"/>
                </div>
                <div class="col-md-12 form-space">
                    <p><small><b>益农商城</b>发货并提供售后服务,今日下单,明日送达</small></p>
                </div>
                <div class="col-md-12 form-space">
                    <input class="btn btn-primary btn-lg btn-block" id="buyNow" type="button" value="立即购买">
                </div>
                <div class="col-md-12 form-space">
                    <button id="btn-add-to-cart" type="button" class="btn btn-default go-cart"><span
                            class="fa fa-cart-plus"></span> 加入购物车
                    </button>
                </div>
            </form>
        </div>
    </div>
    <!--商品信息展示结束-->

    <!--评价展示-->
    <div class="col-md-offset-1 col-md-10">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">买家评价</h2>
            </div>
            <div class="panel-body" id="comment-list">

            </div>
        </div>
    </div>

    <!--售后信息开始-->
    <div class="col-md-offset-1 col-md-10">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h2 class="panel-title">售后保障</h2>
            </div>
            <div class="panel-body ">
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-shield"></span></div>
                    <div class="col-md-11 saled-title">正品保障</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">益农商城向您保证所售商品均为正品，益农商城自营商品开具机打发票或电子发票。</p>
                </div>
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-search-minus"></span></div>
                    <div class="col-md-11 saled-title">产品溯源</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">根据包装二维码可获取农产品原产地信息。</p>
                </div>
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-heartbeat"></span></div>
                    <div class="col-md-11 saled-title">郑重承诺</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">益农商城销售并发货的商品，由益农商城提供发票和相应的售后服务。请您放心购买！
                        <br/>
                        注：因商家会在没有任何提前通知的情况下更改产品包装、产地或者一些附件，本司不能确保客户收到的货物与商城图片、产地、附件说明完全一致。只能保证与当时市场上同样主流新品一致。若本商城没有及时更新，请大家谅解！
                    </p>
                </div>
                <div class="row">
                    <div class="col-md-1 saled-icon"><span class="fa fa-reply"></span></div>
                    <div class="col-md-11 saled-title">无忧退货</div>
                </div>
                <div class="row">
                    <p class="col-md-offset-1 col-md-11 saled-content">
                        客户购买益农商城商品7日内（含7日，自客户收到商品之日起计算），在保证商品完好的前提下，可无理由退货。（部分商品除外，详情请见各商品细则）</p>
                </div>
                <div class="saled-content">
                    <small><b>权利声明：</b><br/>
                        所有商品信息、商品咨询等内容，是益农商城重要的经营资源，未经许可，禁止非法转载使用。<br/>
                        注：本站商品信息均来自于合作方，其真实性、准确性和合法性由信息拥有者（合作方）负责。本站不提供任何保证，并不承担任何法律责任。</small>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页脚开始-->
<div class="clearfix"></div>
<footer class="footer">
    <!-- 品质保障，私人定制等-->
    <div class="text-center rights container">
        <div class="col-md-offset-2 col-md-2">
            <span class="fa fa-thumbs-o-up"></span>
            <p>品质保障</p>
        </div>
        <div class="col-md-2">
            <span class="fa fa-search-minus"></span>
            <p>产地直销</p>
        </div>
        <div class="col-md-2">
            <span class="fa fa-shopping-bag"></span>
            <p>品牌特供</p>
        </div>
        <div class="col-md-2">
            <span class="fa fa-car"></span>
            <p>极速货运</p>
        </div>
    </div>

    <!--联系我们、下载客户端等-->
    <div class="container beforeBottom text-center">
        <div class="col-md-offset-1 col-md-3">

        </div>
        <div class="col-md-4 callus text-center">
            <div class="col-md-4">
                <ul>
                    <li><a href="#"><p>买家帮助</p></a></li>
                    <li><a href="#">新手指南</a></li>
                    <li><a href="#">服务保障</a></li>
                    <li><a href="#">常见问题</a></li>
                </ul>
            </div>
            <div class="col-md-4">
                <ul>
                    <li><a href="#"><p>商家帮助</p></a></li>
                    <li><a href="#">商家入驻</a></li>
                    <li><a href="#">商家后台</a></li>
                </ul>
            </div>
            <div class="col-md-4">
                <ul>
                    <li><a href="#"><p>关于我们</p></a></li>
                    <li><a href="#">关于益农</a></li>
                    <li><a href="#">联系我们</a></li>
                    <li>
                        <span class="fa fa-wechat"></span>
                        <span class="fa fa-weibo"></span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- 页面底部-备案号 #footer -->
    <div class="col-md-12 text-center bottom">
        Copyright © 2022 dnsc.cn All Rights Reserved 京ICP备08963888号-45 <a target="_blank" href="http://www.dnsc.cn/">益农科技集团有限公司</a>
        版权所有
    </div>
</footer>
<!--页脚结束-->
<script type="text/javascript" src="../js/jquery-getUrlParam.js"></script>
<script>
    /**
    * 添加购物车点击事件
    * Integer pid, Integer num, @PathVariable("productPrice") Long price
    **/
    $("#btn-add-to-cart").click(function () {
        $.ajax({
            url: "/cart/putToCart",
            type: "POST",
            async: false,
            data: {
                //向购物车后端传输的数据
                pid: id,
                amount: $("#num").val(),

            },
            dataType: "JSON",
            success: function (json) {
                if (json.stateCode === 200 || json.stateCode === 0) {
                    alert("插入购物车成功");
                    location.href = "cart.html";
                } else if (json.stateCode === 201) {
                    alert("请先登录");
                    console.log(111);
                    location.href = "login.html";
                } else {
                    alert("插入购物车失败");
                }
            },
            error: function (xhr) {
                alert("服务器端产生了 " + xhr.status + " 错误")
            }
        })
    })

    //获取url中的参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]); return null; //返回参数值
    }

    $("#buyNow").click(function () {
        let num = $("#num").val();
        let pid = getUrlParam('id');
        $.ajax({
            url: "/cart/putToCart",
            type: "POST",
            async: false,
            data: {
                //向购物车后端传输的数据
                pid: pid,
                amount: num,
            },
            dataType: "JSON",
            success: function (json) {
                if (json.stateCode === 200 || json.stateCode === 0) {
                    console.log(JSON.stringify(json))
                    location.href = "orderConfirm.html?cids=" + json.cid;
                } else if (json.stateCode === 201) {
                    alert("请先登录");
                    location.href = "login.html";
                } else {
                    alert("购买失败");
                }
            },
            error: function (xhr) {
                alert("服务器端产生了 " + xhr.status + " 错误");
            }
        })
    })
</script>

<!--商品详细页代码-->
<script type="text/javascript">
    let id = $.getUrlParam("id");
    $(document).ready(function () {
        $.ajax({
            url: "/product/" + id + "/selectByPid",
            type: "GET",
            dataType: "JSON",
            success: function (json) {
                if (json.stateCode === 200) {
                    $("#product-title").html(json.data.title);
                    $("#product-sell-point").html(json.data.sellPoint);
                    $("#product-price").html(json.data.price);
                    for (let i = 1; i <= 5; i++) {
                        $("#product-image-" + i + "-big").attr("src", ".." + json.data.image + i + "_big.png");
                        $("#product-image-" + i).attr("src", ".." + json.data.image + i + ".jpg");
                    }
                } else {
                    alert("获取商品详细页失败信息失败！" + json.msg);
                }
            },
            error: function (xhr) {
                alert("服务端报错" + xhr.status)
            }
        });

        //显示评价
        $.ajax({
            url: "/comment/selectCommentByPid?pid=" + id,
            type: "GET",
            dataType: "JSON",
            success: function (json) {
                let list = json.data;
                if (list && list.length > 0) {
                    for (let i = 0; i < list.length; i++) {
                        let div = '<div class="row">\n' +
                            '                    <div class="col-md-11 saled-title">#{username}</div>\n' +
                            '                </div>\n' +
                            '                <div class="row">\n' +
                            '                    <p class="col-md-offset-1 col-md-11">#{comment}</p>\n' +
                            '                </div>';
                        div = div.replace(/#{username}/g, list[i].username);
                        div = div.replace(/#{comment}/g, list[i].comment);
                        $("#comment-list").append(div);
                    }
                } else {
                    let div = '<div class="row">\n' +
                        '                    <div class="col-md-11 saled-title">本商品暂无评价</div>\n' +
                        '                </div>\n'
                    $("#comment-list").append(div);
                }
            },
            error: function (xhr) {
                alert("服务端报错" + xhr.status)
            }
        });
    });
</script>

<script type="text/javascript">
    $(document).ready(function () {
        showName();
    });
</script>
</body>

</html>
